/**
 * jims
 */
package com.jims.master.modules.med.web;

import com.jims.master.common.data.StringData;
import com.jims.master.common.persistence.Page;
import com.jims.master.common.utils.StringUtils;
import com.jims.master.common.web.BaseController;
import com.jims.master.modules.med.entity.MedicalVsPatient;
import com.jims.master.modules.med.service.MedicalComService;
import com.jims.master.modules.med.service.MedicalVsPatientService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 医保卡与his人员关联Controller
 * @author 陈晓阳
 * @version 2017-06-09
 */
@Controller
@RequestMapping(value = "${adminPath}/med/medicalVsPatient")
public class MedicalVsPatientController extends BaseController {

	@Autowired
	private MedicalVsPatientService medicalVsPatientService;
    @Autowired
    private MedicalComService medicalComService;
	
	@ModelAttribute
	public MedicalVsPatient get(@RequestParam(required=false) String id) {
		MedicalVsPatient entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = medicalVsPatientService.get(id);
		}
		if (entity == null){
			entity = new MedicalVsPatient();
		}
		return entity;
	}
	
	@RequiresPermissions("user")
	@RequestMapping(value = {"index", ""})
	public String list(MedicalVsPatient medicalVsPatient, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<MedicalVsPatient> page = medicalVsPatientService.findPage(new Page<MedicalVsPatient>(request, response), medicalVsPatient); 
		model.addAttribute("page", page);
		return "modules/med/medicalVsPatientIndex";
	}

	@RequiresPermissions("user")
	@RequestMapping(value = "form")
	public String form(MedicalVsPatient medicalVsPatient, Model model) {
		model.addAttribute("medicalVsPatient", medicalVsPatient);
		return "modules/med/medicalVsPatientForm";
	}

	@RequiresPermissions("user")
	@RequestMapping(value = "save")
	@ResponseBody
	public StringData save(MedicalVsPatient medicalVsPatient, Model model) {
	    StringData data=new StringData();
		int i=medicalVsPatientService.save(medicalVsPatient);
        if(i>0){
            data.setCode("success");
            data.setData("保存医保卡与his人员关联成功");
        }else{
            data.setCode("error");
            data.setData("保存医保卡与his人员关联失败");
        }
        return data;
	}
	@RequiresPermissions("user")
	@RequestMapping(value = "delete")
	@ResponseBody
	public StringData delete(MedicalVsPatient medicalVsPatient) {
	    StringData data=new StringData();
		int i=medicalVsPatientService.delete(medicalVsPatient);
        if(i>0){
            data.setCode("success");
            data.setData("删除医保卡与his人员关联成功");
        }else{
            data.setCode("error");
            data.setData("删除医保卡与his人员关联失败");
        }
		return data;
	}

    /**
     * 根据门诊号查询医保信息
     * @param medicalVsPatient
     * @param model
     * @return
     */
    @RequiresPermissions("user")
    @RequestMapping(value = "findByClinicNo")
    @ResponseBody
    public StringData findByClinicNo(MedicalVsPatient medicalVsPatient, Model model) {
        StringData data=new StringData();
        boolean isLocal=medicalVsPatientService.findByClinicNo(medicalVsPatient);
        if(isLocal){
            data.setCode("success");
        }else{
            data.setCode("error");
        }
        return data;
    }

}